package com.ssy.lingxi.platform.template.service.repository;

import com.ssy.lingxi.platform.template.service.entity.door.MemberPurchase;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MemberPurchaseRepository extends JpaRepository<MemberPurchase, Long> {

    MemberPurchase findByMemberIdAndRoleId(Long memberId, Long roleId);

    List<MemberPurchase> findByRoleId(Long roleId);

    @Query(value = "SELECT * FROM pt_member_purchase WHERE create_time > :timeInMillis ORDER BY create_time DESC limit 5", nativeQuery = true)
    List<MemberPurchase> findNewAddMemberPurchase(@Param("timeInMillis") long timeInMillis);

    Boolean existsByMemberIdAndRoleId(Long memberId, Long memberRoleId);
}
